package com.lwj.liwanjia.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.lwj.liwanjia.R;
import com.lwj.liwanjia.bean.MarketFDBean;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by Administrator on 2017/9/7.
 */

public class MyGridAdapter extends BaseAdapter {
    private int section;
    private Context context;
    private List<MarketFDBean.DataBean> list;

    public MyGridAdapter(Context context, List<MarketFDBean.DataBean> list, int section) {
        this.list = list;
        this.section = section;
        this.context = context;
        inflater = LayoutInflater.from(context);
    }

    private LayoutInflater inflater;

    @Override
    public int getCount() {
        return list.get(section).getGoodsType().size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(section).getGoodsType().get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null) {
            convertView = inflater.inflate(R.layout.right_grid_item, parent, false);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        holder.marketShangpinName.setText(list.get(section).getGoodsType().get(position).getName());
        Glide.with(context).load(list.get(section).getGoodsType().get(position).getImageUrl()).placeholder(R.mipmap.station).error(R.mipmap.station).into(holder.marketShangpinImage);
        return convertView;
    }

    static class ViewHolder {
        @BindView(R.id.market_shangpin_image)
        ImageView marketShangpinImage;
        @BindView(R.id.market_shangpin_name)
        TextView marketShangpinName;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
